package com.syzg.view.tags;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;

import com.syzg.core.util.StringUtil;

public class ColumnTag extends SimpleTagSupport {
	
    private String headerTitle;
    private String width;
    private String align;
    private String cssHClass;
    private String cssHStyle;
    private String cssDClass;
    private String cssDStyle;

	public void setHeaderTitle(String headerTitle) {
		this.headerTitle = headerTitle;
	}

	public void setWidth(String width) {
		this.width = width;
	}

	public void setAlign(String align) {
		this.align = align;
	}

	public String getCssHClass() {
		return cssHClass;
	}

	public void setCssHClass(String cssHClass) {
		this.cssHClass = cssHClass;
	}

	public String getCssHStyle() {
		return cssHStyle;
	}

	public void setCssHStyle(String cssHStyle) {
		this.cssHStyle = cssHStyle;
	}

	public String getCssDClass() {
		return cssDClass;
	}

	public void setCssDClass(String cssDClass) {
		this.cssDClass = cssDClass;
	}

	public String getCssDStyle() {
		return cssDStyle;
	}

	public void setCssDStyle(String cssDStyle) {
		this.cssDStyle = cssDStyle;
	}

	@Override
	public void doTag() throws JspException, IOException {
		JspWriter out = this.getJspContext().getOut();
		
		String flag = (String)getJspContext().getAttribute("headFlag");
		
		StringBuffer sb = new StringBuffer();
		if(flag.equals("true")){
			sb.append("<th");
			if(StringUtil.isNotEmpty(cssHClass)){
				sb.append(" class=\"" + cssHClass + "\"");
			}
			if(StringUtil.isNotEmpty(cssHStyle)){
				sb.append(" style=\"" + cssHStyle + "\"");
			}
			if(StringUtil.isNotEmpty(width)){
				sb.append(" width=\"" + width + "\"");
			}
			if(StringUtil.isNotEmpty(align)){
				sb.append(" align=\"" + align + "\"");
			}
			sb.append(">");
			sb.append(headerTitle);
			sb.append("</th>");
			out.println(sb.toString());
		} else {
			sb.append("<td");
			if(StringUtil.isNotEmpty(cssDClass)){
				sb.append(" class=\"" + cssDClass + "\"");
			}
			if(StringUtil.isNotEmpty(cssDStyle)){
				sb.append(" style=\"" + cssDStyle + "\"");
			}
			if(StringUtil.isNotEmpty(width)){
				sb.append(" width=\"" + width + "\"");
			}
			if(StringUtil.isNotEmpty(align)){
				sb.append(" align=\"" + align + "\"");
			}
			sb.append(">");
			out.println(sb.toString());

			JspFragment jf = this.getJspBody();
			jf.invoke(null);
			out.println("</td>");
		}
	}
}
